package qldc.pm.tienan.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import qldc.pm.tienan.service.ClpSerializer;
import qldc.pm.tienan.service.CongViecBanGiaoLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;


public class CongViecBanGiaoClp extends BaseModelImpl<CongViecBanGiao>
    implements CongViecBanGiao {
    private long _congViecBanGiaoId;
    private long _bienBanBanGiaoHoSoId;
    private String _tenCongViec;
    private String _tienDoThucHien;
    private String _chuThich;
    private BaseModel<?> _congViecBanGiaoRemoteModel;

    public CongViecBanGiaoClp() {
    }

    @Override
    public Class<?> getModelClass() {
        return CongViecBanGiao.class;
    }

    @Override
    public String getModelClassName() {
        return CongViecBanGiao.class.getName();
    }

    @Override
    public long getPrimaryKey() {
        return _congViecBanGiaoId;
    }

    @Override
    public void setPrimaryKey(long primaryKey) {
        setCongViecBanGiaoId(primaryKey);
    }

    @Override
    public Serializable getPrimaryKeyObj() {
        return _congViecBanGiaoId;
    }

    @Override
    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    @Override
    public Map<String, Object> getModelAttributes() {
        Map<String, Object> attributes = new HashMap<String, Object>();

        attributes.put("congViecBanGiaoId", getCongViecBanGiaoId());
        attributes.put("bienBanBanGiaoHoSoId", getBienBanBanGiaoHoSoId());
        attributes.put("tenCongViec", getTenCongViec());
        attributes.put("tienDoThucHien", getTienDoThucHien());
        attributes.put("chuThich", getChuThich());

        return attributes;
    }

    @Override
    public void setModelAttributes(Map<String, Object> attributes) {
        Long congViecBanGiaoId = (Long) attributes.get("congViecBanGiaoId");

        if (congViecBanGiaoId != null) {
            setCongViecBanGiaoId(congViecBanGiaoId);
        }

        Long bienBanBanGiaoHoSoId = (Long) attributes.get(
                "bienBanBanGiaoHoSoId");

        if (bienBanBanGiaoHoSoId != null) {
            setBienBanBanGiaoHoSoId(bienBanBanGiaoHoSoId);
        }

        String tenCongViec = (String) attributes.get("tenCongViec");

        if (tenCongViec != null) {
            setTenCongViec(tenCongViec);
        }

        String tienDoThucHien = (String) attributes.get("tienDoThucHien");

        if (tienDoThucHien != null) {
            setTienDoThucHien(tienDoThucHien);
        }

        String chuThich = (String) attributes.get("chuThich");

        if (chuThich != null) {
            setChuThich(chuThich);
        }
    }

    @Override
    public long getCongViecBanGiaoId() {
        return _congViecBanGiaoId;
    }

    @Override
    public void setCongViecBanGiaoId(long congViecBanGiaoId) {
        _congViecBanGiaoId = congViecBanGiaoId;

        if (_congViecBanGiaoRemoteModel != null) {
            try {
                Class<?> clazz = _congViecBanGiaoRemoteModel.getClass();

                Method method = clazz.getMethod("setCongViecBanGiaoId",
                        long.class);

                method.invoke(_congViecBanGiaoRemoteModel, congViecBanGiaoId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getBienBanBanGiaoHoSoId() {
        return _bienBanBanGiaoHoSoId;
    }

    @Override
    public void setBienBanBanGiaoHoSoId(long bienBanBanGiaoHoSoId) {
        _bienBanBanGiaoHoSoId = bienBanBanGiaoHoSoId;

        if (_congViecBanGiaoRemoteModel != null) {
            try {
                Class<?> clazz = _congViecBanGiaoRemoteModel.getClass();

                Method method = clazz.getMethod("setBienBanBanGiaoHoSoId",
                        long.class);

                method.invoke(_congViecBanGiaoRemoteModel, bienBanBanGiaoHoSoId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getTenCongViec() {
        return _tenCongViec;
    }

    @Override
    public void setTenCongViec(String tenCongViec) {
        _tenCongViec = tenCongViec;

        if (_congViecBanGiaoRemoteModel != null) {
            try {
                Class<?> clazz = _congViecBanGiaoRemoteModel.getClass();

                Method method = clazz.getMethod("setTenCongViec", String.class);

                method.invoke(_congViecBanGiaoRemoteModel, tenCongViec);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getTienDoThucHien() {
        return _tienDoThucHien;
    }

    @Override
    public void setTienDoThucHien(String tienDoThucHien) {
        _tienDoThucHien = tienDoThucHien;

        if (_congViecBanGiaoRemoteModel != null) {
            try {
                Class<?> clazz = _congViecBanGiaoRemoteModel.getClass();

                Method method = clazz.getMethod("setTienDoThucHien",
                        String.class);

                method.invoke(_congViecBanGiaoRemoteModel, tienDoThucHien);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getChuThich() {
        return _chuThich;
    }

    @Override
    public void setChuThich(String chuThich) {
        _chuThich = chuThich;

        if (_congViecBanGiaoRemoteModel != null) {
            try {
                Class<?> clazz = _congViecBanGiaoRemoteModel.getClass();

                Method method = clazz.getMethod("setChuThich", String.class);

                method.invoke(_congViecBanGiaoRemoteModel, chuThich);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    public BaseModel<?> getCongViecBanGiaoRemoteModel() {
        return _congViecBanGiaoRemoteModel;
    }

    public void setCongViecBanGiaoRemoteModel(
        BaseModel<?> congViecBanGiaoRemoteModel) {
        _congViecBanGiaoRemoteModel = congViecBanGiaoRemoteModel;
    }

    public Object invokeOnRemoteModel(String methodName,
        Class<?>[] parameterTypes, Object[] parameterValues)
        throws Exception {
        Object[] remoteParameterValues = new Object[parameterValues.length];

        for (int i = 0; i < parameterValues.length; i++) {
            if (parameterValues[i] != null) {
                remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
            }
        }

        Class<?> remoteModelClass = _congViecBanGiaoRemoteModel.getClass();

        ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

        Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

        for (int i = 0; i < parameterTypes.length; i++) {
            if (parameterTypes[i].isPrimitive()) {
                remoteParameterTypes[i] = parameterTypes[i];
            } else {
                String parameterTypeName = parameterTypes[i].getName();

                remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
            }
        }

        Method method = remoteModelClass.getMethod(methodName,
                remoteParameterTypes);

        Object returnValue = method.invoke(_congViecBanGiaoRemoteModel,
                remoteParameterValues);

        if (returnValue != null) {
            returnValue = ClpSerializer.translateOutput(returnValue);
        }

        return returnValue;
    }

    @Override
    public void persist() throws SystemException {
        if (this.isNew()) {
            CongViecBanGiaoLocalServiceUtil.addCongViecBanGiao(this);
        } else {
            CongViecBanGiaoLocalServiceUtil.updateCongViecBanGiao(this);
        }
    }

    @Override
    public CongViecBanGiao toEscapedModel() {
        return (CongViecBanGiao) ProxyUtil.newProxyInstance(CongViecBanGiao.class.getClassLoader(),
            new Class[] { CongViecBanGiao.class },
            new AutoEscapeBeanHandler(this));
    }

    @Override
    public Object clone() {
        CongViecBanGiaoClp clone = new CongViecBanGiaoClp();

        clone.setCongViecBanGiaoId(getCongViecBanGiaoId());
        clone.setBienBanBanGiaoHoSoId(getBienBanBanGiaoHoSoId());
        clone.setTenCongViec(getTenCongViec());
        clone.setTienDoThucHien(getTienDoThucHien());
        clone.setChuThich(getChuThich());

        return clone;
    }

    @Override
    public int compareTo(CongViecBanGiao congViecBanGiao) {
        int value = 0;

        if (getCongViecBanGiaoId() < congViecBanGiao.getCongViecBanGiaoId()) {
            value = -1;
        } else if (getCongViecBanGiaoId() > congViecBanGiao.getCongViecBanGiaoId()) {
            value = 1;
        } else {
            value = 0;
        }

        value = value * -1;

        if (value != 0) {
            return value;
        }

        return 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof CongViecBanGiaoClp)) {
            return false;
        }

        CongViecBanGiaoClp congViecBanGiao = (CongViecBanGiaoClp) obj;

        long primaryKey = congViecBanGiao.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(11);

        sb.append("{congViecBanGiaoId=");
        sb.append(getCongViecBanGiaoId());
        sb.append(", bienBanBanGiaoHoSoId=");
        sb.append(getBienBanBanGiaoHoSoId());
        sb.append(", tenCongViec=");
        sb.append(getTenCongViec());
        sb.append(", tienDoThucHien=");
        sb.append(getTienDoThucHien());
        sb.append(", chuThich=");
        sb.append(getChuThich());
        sb.append("}");

        return sb.toString();
    }

    @Override
    public String toXmlString() {
        StringBundler sb = new StringBundler(19);

        sb.append("<model><model-name>");
        sb.append("qldc.pm.tienan.model.CongViecBanGiao");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>congViecBanGiaoId</column-name><column-value><![CDATA[");
        sb.append(getCongViecBanGiaoId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>bienBanBanGiaoHoSoId</column-name><column-value><![CDATA[");
        sb.append(getBienBanBanGiaoHoSoId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>tenCongViec</column-name><column-value><![CDATA[");
        sb.append(getTenCongViec());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>tienDoThucHien</column-name><column-value><![CDATA[");
        sb.append(getTienDoThucHien());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>chuThich</column-name><column-value><![CDATA[");
        sb.append(getChuThich());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
